var UrlHelper = function (href) {
    var url = href.toLowerCase();
    var mark = url.indexOf("?");
    if (mark < 0) {
        this.host = url;
        return this;
    }
    this.host = url.substring(0, mark);
    var paramstr = url.substring(mark + 1);
    var submark = paramstr.indexOf("?");
    if (submark >= 0) {
        var hold = paramstr.substring(submark + 1);
        paramstr = paramstr.substring(0, submark);
    }
    var paramPairs = paramstr.split("&");
    var len = paramPairs.length;
    var temp;
    for (var i = len - 1; i--;) {
        temp = paramPairs[i].split("=");
        this.paramSet[temp[0]] = temp[1];
    }
    temp = paramPairs[len - 1].split("=");
    if (submark >= 0) {
        var k = {};
        this.holdMark = temp[0];
        k[temp[0]] = temp[1] + "?" + hold;
        this.holdKeyPair = k;
    } else this.paramSet[temp[0]] = temp[1];
};
UrlHelper.prototype = {
    host: "",
    paramSet: {},
    holdKeyPair: null,
    holdMark: "",
    param: function (key) {
        if (this.holdMark === key) return this.holdKeyPair[key];
        return this.paramSet[key];
    },
    setParam: function (key, value) {
        if (this.holdMark === key) this.holdKeyPair[key] = value;
        else this.paramSet[key] = value;
        return this;
    },
    getUrl: function () {
        var index = 0;
        var str = "";
        var copy = this.paramSet;
        for (var items in copy) {
            str += (items + "=" + copy[items] + "&");
            index++;
        }
        var temp = this.holdMark;
        if (temp !== "") {
            str += (temp + "=" + this.holdKeyPair[temp] + "&");
            index++;
        }
        if (index) {
            str = str.substring(0, str.length - 1);
            return this.host + "?" + str;
        }
        return this.host;
    },
    removeParam: function (key) {
        if (this.holdMark === key) {
            this.holdMark = "";
            this.holdKeyPair = null;
            return this;
        }
        if (this.paramSet[key]) {
            var k = {};
            var temp = this.paramSet;
            for (var items in temp) {
                if (items !== key) k[items] = temp[items];
            }
            this.paramSet = k;
        }
        return this;
    }
};
export default UrlHelper